package com.bravo.article.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.bravo.article.entity.Article;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * article数据访问接口
 * @author Yuyong
 *
 */
public interface ArticleRepository extends JpaRepository<Article,String>,JpaSpecificationExecutor<Article>{

    /**
     * 审核
     * @param id
     */
    @Transactional
    @Modifying
    @Query(value = "update tb_article set state = 1 where id  = ?1",nativeQuery = true)
    void examine(String id);

    /**
     * 点赞
     * @param id
     * @return
     */
    @Transactional
    @Modifying
    @Query(value = "update tb_article a set thumbup = thumbup + 1 where id = ?1",nativeQuery = true)
    int updateThumbup(String id);
}
